package 斗地主;

import java.util.*;


public class test_1 {
	
	
	//因为全局中只有一副牌供给大家使用，所以定义为静态的
		public static List<Card> c =new ArrayList<Card>(); 

		//使用静态代码块初始化牌
		static {
			String[] Number= {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
			String[] Color= {"红桃","黑桃","方片","梅花"};
			int Size = 2;//记录牌的实际大小，方便后面用比较器比较
			for (String msize : Number) {
				Size++;
				
				for (String mcolor : Color) {
					
					Card card=new Card(msize, mcolor,Size); //每一个点数和花色组成一个牌对象
					c.add(card); //把牌对象放入牌集合
					
				}
				
			}
			//把大王和小王加入到牌集合
			Card xiaowang = new Card("", "小王",++Size);
			Card dawang = new Card("", "大王",++Size);
			Collections.addAll(c,dawang, xiaowang); //把大王小王加入牌对象
			
		}
	

	public static void main(String[] args) {
	
				System.out.println("原始的牌"+c);
			
				Collections.shuffle(c);//洗牌
				System.out.println("洗好的牌"+c);
				//定义三个玩家，拿3个容器去装牌
				List<Card> play1=new ArrayList<>();
				List<Card> play2=new ArrayList<>();
				List<Card> play3=new ArrayList<>();
				
				//发牌
				//一共有54张牌，发五十一张，留3张底牌
				for (int i=0;i<c.size()-3;i++) {
					if(i%3==0) {
						play1.add(c.get(i));
					}
					if(i%3==1) {
						play2.add(c.get(i));
						
					}
					if(i%3==2) {
						play3.add(c.get(i));
					}
				}
				sortCard(play1);
				sortCard(play2);
				sortCard(play3);
				System.out.println("----------------");
				System.out.println("play1的牌："+play1);
				System.out.println("play2的牌："+play2);
				System.out.println("play3的牌："+play3);
				//Collections.sort((play1);????
	}
	
/*
	public int compare(Student o1, Student o2) {
		int result = o1.name.compareTo(o2.name);
		if(result == 0) {
			result = Integer.compare(o1.age, o2.age);
		}
		return result;
*/
	private static void sortCard(List<Card> player) {  //排序
		
		Collections.sort(player,new Comparator<Card>() {
			@Override
			public int compare(Card o1, Card o2) {
				//Card.sort(player);
				//if(o1.Size.compareTo(o2.))
				return  o2.getIndex()-o1.getIndex();//牌由大到小放置
			}
		});
		
	}
	


}
